﻿//============================================================
//write by bxl at 2021-06-13 22:11:41
//============================================================



using System.Collections.Generic;
using System;
using BCService.Utils;
using BCCommon;
using BCData.CRM.BigCustomerTradeRecord;
using BCDto.CRM.BigCustomerTradeRecord;
using BCEntity.CRM.BigCustomerTradeRecord;
using BCDto.Sim.Admin.Admin;

namespace BCService.CRM.BigCustomerTradeRecord
{
    public class BigCustomerTradeRecordService : IBigCustomerTradeRecordService
    {
        #region var
        private readonly IDatabaseContext databaseContext;
        private IBigCustomerTradeRecordData bigCustomerTradeRecordData;


        #endregion

        #region 构造函数
        public BigCustomerTradeRecordService(IBigCustomerTradeRecordData bigCustomerTradeRecordData, IDatabaseContext databaseContext)
        {
            this.bigCustomerTradeRecordData = bigCustomerTradeRecordData;
            this.databaseContext = databaseContext;
        }
        #endregion

        #region Add
        /// <summary>
        /// 添加新大客户交易记录纪录
        /// </summary>
        /// <param name="bigCustomerTradeRecordRequestDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public BigCustomerTradeRecordDto Add(BigCustomerTradeRecordRequestDto bigCustomerTradeRecordRequestDto, AdminDto admin)
        {
            return bigCustomerTradeRecordData.InsertAsync(bigCustomerTradeRecordRequestDto.As<BigCustomerTradeRecordEntity>()).GetAwaiter().GetResult().As<BigCustomerTradeRecordDto>();
        }
        #endregion

        #region update
        /// <summary>
        /// 修改大客户交易记录记录
        /// </summary>
        /// <param name="bigCustomerTradeRecordDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public BigCustomerTradeRecordDto Update(BigCustomerTradeRecordDto bigCustomerTradeRecordDto, AdminDto admin)
        {
            return bigCustomerTradeRecordData.UpdateAsync(bigCustomerTradeRecordDto.As<BigCustomerTradeRecordEntity>()).GetAwaiter().GetResult().As<BigCustomerTradeRecordDto>();

        }
        #endregion

        #region Delete
        /// <summary>
        /// 删除大客户交易记录记录
        /// </summary>
        /// <param name="bigCustomerTradeRecordId"></param>
        /// <returns></returns>
        public void Delete(long bigCustomerTradeRecordId)
        {
            bigCustomerTradeRecordData.DeleteAsync(bigCustomerTradeRecordId).GetAwaiter().GetResult();

        }
        #endregion

        #region GetByBigCustomerTradeRecordId
        /// <summary>
        /// 获取大客户交易记录记录
        /// </summary>
        /// <param name="bigCustomerTradeRecordId"></param>
        /// <returns></returns>
        public BigCustomerTradeRecordDto GetById(long bigCustomerTradeRecordId)
        {
            var a = bigCustomerTradeRecordData.GetEntityAsync(bigCustomerTradeRecordId).GetAwaiter().GetResult();
            return a.As<BigCustomerTradeRecordDto>();
        }
        #endregion

        #region GetList  获取大客户交易记录记录--[分页]
        public PageableList<BigCustomerTradeRecordDto> GetList(int pageIndex, int pageSize)
        {
            int fCount = 0;
            IEnumerable<BigCustomerTradeRecordEntity> fList;

            (fList, fCount) = bigCustomerTradeRecordData.GetListAsync(pageIndex, pageSize).GetAwaiter().GetResult();

            return new PageableList<BigCustomerTradeRecordDto>()
            {
                Count = fCount,
                Items = fList.As<IEnumerable<BigCustomerTradeRecordDto>>(),
                PageIndex = pageIndex,
                PageSize = pageSize,
                ServerTime = DateTime.Now,
            };
        }
        #endregion
    }
}